﻿Public Class KeToanTienMat
    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, keyData As System.Windows.Forms.Keys) As Boolean
        If keyData = (Keys.Control Or Keys.N) Then
            Me.KetoantienmatIUltraGrid_ThongTin.setMacDinh("ma", getMa)
            Return Me.KetoantienmatIUltraGrid_ThongTin.getTaoMoi()
        End If
        If keyData = (Keys.Control Or Keys.S) Then
            Me.KetoantienmatIUltraGrid_ThongTin.getLuu()
            Return True
        End If
        If keyData = (Keys.Control Or Keys.D) Then
            Return Me.KetoantienmatIUltraGrid_ThongTin.getXoa()
        End If
        If keyData = (Keys.Control Or Keys.P) Then
            'Return Me.getIn()
        End If
        If keyData = (Keys.Control Or Keys.R) Then
            Return Me.KetoantienmatIUltraGrid_ThongTin.getRefresh()
        End If
        If keyData = (Keys.Control Or Keys.Q) Then
            Return getThoat()
        End If
        Return MyBase.ProcessCmdKey(msg, keyData)
    End Function
    'mã tự động của phiếu
    Private Function getMa() As String
        'Dim ma As String = Me.HttientoTableAdapter.getMaKeToanTienMat(New Date(2012, 4, 1), New Date(2012, 4, 30))
        'If IsNothing(ma) Then
        '    Return Today.Year & Today.Month & Today.Day
        'Else
        '    Return ma
        'End If
        Return ""
    End Function
    Private Sub KeToanTienMat_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Cursor = Cursors.WaitCursor
        'load dữ liệu
        Me.Dmtaikhoancap2TableAdapter.Fill(Me.ErpharmaDataSet.dmtaikhoancap2)
        Me.DmphongbanTableAdapter1.Fill(Me.ErpharmaDataSet.dmphongban)
        Me.DmloainhanvienTableAdapter.Fill(Me.ErpharmaDataSet.dmloainhanvien)
        Me.DmnhanvienTableAdapter.Fill(Me.ErpharmaDataSet.dmnhanvien)
        Me.DmtinhtrangTableAdapter.Fill(Me.ErpharmaDataSet.dmtinhtrang)
        Me.DmloaitienTableAdapter.Fill(Me.ErpharmaDataSet.dmloaitien)
        Me.DmtinhtrangphieuTableAdapter.Fill(Me.ErpharmaDataSet.dmtinhtrangphieu)
        Me.DmthoigianTableAdapter.Fill(Me.ErpharmaDataSet.dmthoigian)
        Me.DmnhanvienbanhangTableAdapter.Fill(Me.ErpharmaDataSet.dmnhanvienbanhang)
        ' Me.DmkhachhangTableAdapter.Fill(Me.ErpharmaDataSet.dmkhachhang)
        Me.DmnghiepvuTableAdapter.Fill(Me.ErpharmaDataSet.dmnghiepvu)
        Me.KetoantienmatTableAdapter.Fill(Me.ErpharmaDataSet.ketoantienmat)
        '=======================================================================
        'set doi tuong
        Me.DmthoigianIUltraCombo.setDataTable(Me.ErpharmaDataSet.dmthoigian) 'iultracombo
        Me.DmloaitienIUltraComBoEditor.setThemUltraGrid(Me.DmloaitienIUltraGrid) 'iultracomboeditor
        Me.dmkhachhangIUltraComBoEditor1.setThemUltraGrid(Me.DmKhachHangIUltraGrid1)
        '=======================================================================
        'set doi tuong cho ultragrid
        Me.KetoantienmatIUltraGrid_DanhSach.setDoiTuongXuLyDuLieu(Me.ErpharmaDataSet.ketoantienmat, Me.KetoantienmatBindingSource, Me.KetoantienmatTableAdapter, Me.ErpharmaDataSet)
        Me.KetoantienmatIUltraGrid_ThongTin.setDoiTuongXuLyDuLieu(Me.ErpharmaDataSet.ketoantienmat, Me.KetoantienmatBindingSource, Me.KetoantienmatTableAdapter, Me.ErpharmaDataSet)
        Me.KetoantienmatIUltraGrid_TienTe.setDoiTuongXuLyDuLieu(Me.ErpharmaDataSet.ketoantienmat, Me.KetoantienmatBindingSource, Me.KetoantienmatTableAdapter, Me.ErpharmaDataSet)
        Me.DmloaitienIUltraGrid.setDoiTuongXuLyDuLieu(Me.ErpharmaDataSet.dmloaitien, Me.DmloaitienBindingSource, Me.DmloaitienTableAdapter, Me.ErpharmaDataSet)
        Me.DmnhanvienIUltraGrid.setDoiTuongXuLyDuLieu(Me.ErpharmaDataSet.dmnhanvien, Me.DmnhanvienBindingSource, Me.DmnhanvienTableAdapter, Me.ErpharmaDataSet)
        '=======================================================================
        'set giao dien
        Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.setGiaoDienTuyBien()
        Me.KetoantienmatIUltraGrid_ThongTin.setGiaoDien_Doi_ThongTin()
        Me.KetoantienmatIUltraGrid_TienTe.setGiaoDien_Doi_ThongTin()
        Me.Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.setGiaoDienTuyBien()
        Me.Ketoantienmatchitiet_ThongTinChinh_TimKiem_IUltraGrid.setGiaoDienTuyBien()
        Me.Ketoantienmatchitiet_ThongTinKhaiThue_TimKiem_IUltraGrid.setGiaoDienTuyBien()
        Me.KetoantienmatIUltraGrid_DanhSach.setGiaoDienTuDong()
        Me.DmthoigianIUltraCombo.setGiaoDien()
        Me.DmnghiepvuIUltraDropDown.setGiaoDien_An_ColumnHeader()
        Me.DmtinhtrangphieuIUltraDropDown.setGiaoDien_An_ColumnHeader()
        Me.DmnhanvienbanhangIUltraDropDown.setGiaoDien()
        Me.DmloaitienIUltraDropDown.setGiaoDien_An_ColumnHeader()
        Me.DmkhachhangIUltraDropDown.setGiaoDien()
        Me.DmloaitienIUltraGrid.setGiaoDienVua()
        Me.DmtinhtrangIUltraDropDown.setGiaoDien()
        Me.DmnhanvienIUltraDropDown.setGiaoDien()
        Me.DmphongbanIUltraDropDown.setGiaoDien()
        Me.Dmtaikhoancap2IUltraDropDown.setGiaoDien_An_ColumnHeader()
        Me.Dmtaikhoancap2IUltraDropDown1.setGiaoDien_An_ColumnHeader()
        Me.DmphongbanIUltraCombo.setGiaoDien_An_ColumnHeader()
        Me.dmkhachhangultragrid.setGiaoDienTuDong()
        Me.DmKhachHangIUltraGrid1.setGiaoDienTuDong()
        '=======================================================================
        'set them ultradropdown
        Me.KetoantienmatIUltraGrid_DanhSach.setThemIUltraDropDown(Me.DmnghiepvuIUltraDropDown, Me.ErpharmaDataSet.dmnghiepvu)
        Me.KetoantienmatIUltraGrid_ThongTin.setThemIUltraDropDown(Me.DmnghiepvuIUltraDropDown, Me.ErpharmaDataSet.dmnghiepvu)
        Me.KetoantienmatIUltraGrid_DanhSach.setThemIUltraDropDown(Me.DmtinhtrangphieuIUltraDropDown, Me.ErpharmaDataSet.dmtinhtrangphieu)
        Me.KetoantienmatIUltraGrid_ThongTin.setThemIUltraDropDown(Me.DmtinhtrangphieuIUltraDropDown, Me.ErpharmaDataSet.dmtinhtrangphieu)
        Me.KetoantienmatIUltraGrid_DanhSach.setThemIUltraDropDown(Me.DmnhanvienbanhangIUltraDropDown, Me.ErpharmaDataSet.dmnhanvienbanhang)
        Me.KetoantienmatIUltraGrid_ThongTin.setThemIUltraDropDown(Me.DmnhanvienbanhangIUltraDropDown, Me.ErpharmaDataSet.dmnhanvienbanhang)
        Me.KetoantienmatIUltraGrid_DanhSach.setThemIUltraDropDown(Me.DmloaitienIUltraDropDown, Me.ErpharmaDataSet.dmloaitien)
        Me.KetoantienmatIUltraGrid_ThongTin.setThemIUltraDropDown(Me.DmloaitienIUltraDropDown, Me.ErpharmaDataSet.dmloaitien)
        Me.KetoantienmatIUltraGrid_DanhSach.setThemIUltraDropDown(Me.DmkhachhangIUltraDropDown, Me.ErpharmaDataSet.dmkhachhang)
        Me.KetoantienmatIUltraGrid_ThongTin.setThemIUltraDropDown(Me.DmkhachhangIUltraDropDown, Me.ErpharmaDataSet.dmkhachhang)
        Me.DmloaitienIUltraGrid.setThemIUltraDropDown(Me.DmtinhtrangIUltraDropDown, Me.ErpharmaDataSet.dmtinhtrang)
        Me.KetoantienmatIUltraGrid_TienTe.setThemIUltraDropDown(Me.DmloaitienIUltraDropDown, Me.ErpharmaDataSet.dmloaitien)
        '=======================================================================
        'lấy dữ liệu từ bộ phận
        Dim htbophan As Hashtable = New Hashtable
        htbophan.Add("bophan", "bophan")
        Me.KetoantienmatIUltraGrid_ThongTin.setThemIUltraDropDown(Me.DmnhanvienIUltraDropDown, Me.ErpharmaDataSet.dmnhanvien, htbophan)
        Me.KetoantienmatIUltraGrid_ThongTin.setThemIUltraDropDown(Me.DmphongbanIUltraDropDown, Me.ErpharmaDataSet.dmphongban)
        Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.setThemIUltraDropDown(Me.Dmtaikhoancap2IUltraDropDown, Me.ErpharmaDataSet.dmtaikhoancap2)
        Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.setThemIUltraDropDown(Me.Dmtaikhoancap2IUltraDropDown1, Me.ErpharmaDataSet.dmtaikhoancap2)
        Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.setThemIUltraDropDown(Me.DmkhachhangIUltraDropDown, Me.ErpharmaDataSet.dmkhachhang)
        Me.DmnhanvienIUltraGrid.setThemIUltraDropDown(Me.DmphongbanIUltraDropDown, Me.ErpharmaDataSet.dmphongban)
        Me.DmnhanvienIUltraGrid.setThemIUltraDropDown(Me.DmloainhanvienIUltraDropDown, ErpharmaDataSet.dmloainhanvien)
        Me.Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.setThemIUltraDropDown(Me.DmkhachhangIUltraDropDown, ErpharmaDataSet.dmkhachhang)
        '=======================================================================
        'set thêm iultracomboeditor
        Me.KetoantienmatIUltraGrid_ThongTin.setUltraComboEditor(Me.DmloaitienIUltraComBoEditor)
        Me.KetoantienmatIUltraGrid_ThongTin.setUltraComboEditor(Me.dmkhachhangultracomboeditor)
        Me.DmloaitienIUltraGrid.setUltraComboEditor(Me.DmloaitienIUltraComBoEditor)
        Me.DmnhanvienIUltraGrid.setUltraComboEditor(Me.DmnhanvienIUltraComBoEditor)
        Me.dmkhachhangultragrid.setUltraComboEditor(Me.dmkhachhangultracomboeditor)
        Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.setUltraComboEditor(Me.dmkhachhangIUltraComBoEditor1)
        '=======================================================================
        'set tìm kiếm
        Me.KetoantienmatIUltraGrid_DanhSach.setTimKiemTrenCotUltraGrid()
        Me.Ketoantienmatchitiet_ThongTinChinh_TimKiem_IUltraGrid.setTimKiemTrenCotUltraGrid()
        Me.Ketoantienmatchitiet_ThongTinKhaiThue_TimKiem_IUltraGrid.setTimKiemTrenCotUltraGrid()
        Me.dmkhachhangultragrid.setTimKiemTrenCotUltraGrid()
        Me.DmKhachHangIUltraGrid1.setTimKiemTrenCotUltraGrid()
        '=======================================================================
        'set giá trị mặt định
        Me.KetoantienmatIUltraGrid_ThongTin.setMacDinh("loaitien", "VND")
        Me.KetoantienmatIUltraGrid_ThongTin.setMacDinh("tygia", 1)
        Me.KetoantienmatIUltraGrid_ThongTin.setMacDinh("nguyente", 0)
        Me.KetoantienmatIUltraGrid_ThongTin.setMacDinh("tienvnd", 0)
        Me.KetoantienmatIUltraGrid_ThongTin.setMacDinh("sochungtu", "")
        Me.KetoantienmatIUltraGrid_ThongTin.setMacDinh("ngaylap", Today)
        Me.KetoantienmatIUltraGrid_ThongTin.setMacDinh("ngaylapthamchieu", Today)
        Me.Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.setMacDinh("tongcong", 0)
        Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.setMacDinh("nguyente", 0)
        Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.setMacDinh("tienvnd", 0)
        Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.setMacDinh("doanhthu", 0)
        Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.setMacDinh("ngayhoadon", Today)
        Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.setMacDinh("ngaylapthamchieu", Today)
        Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.setMacDinh("ngay", Today)
        Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.setMacDinh("phantramthue", 0)
        Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.setMacDinh("thue", 0)
        Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.setMacDinh("tongcong", 0)
        Me.Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.setMacDinh("phantramthue", 0)
        Me.Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.setMacDinh("thue", 0)
        Me.Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.setMacDinh("tongcong", 0)
        Me.Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.setMacDinh("trangthai", "TL")
        '=======================================================================
        'set cot bat loi
        Me.KetoantienmatIUltraGrid_ThongTin.setCotBatLoi("nghiepvu")
        Me.KetoantienmatIUltraGrid_ThongTin.setCotBatLoi("donvi")
        '=======================================================================
        'set group by - iultragrid timkiem
        Me.Ketoantienmatchitiet_ThongTinChinh_TimKiem_IUltraGrid.setGroupBy("ma")
        Me.Ketoantienmatchitiet_ThongTinKhaiThue_TimKiem_IUltraGrid.setGroupBy("ma")
        '=======================================================================
        'set menustrip
        Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.setChoPhepMenuStrip()
        Me.Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.setChoPhepMenuStrip()
        Me.DmloaitienIUltraGrid.setChoPhepMenuStrip()
        Me.DmnhanvienIUltraComBoEditor.setThemUltraGrid(Me.DmnhanvienIUltraGrid)
        Me.dmkhachhangultracomboeditor.setThemUltraGrid(Me.dmkhachhangultragrid)
        Me.DmnhanvienIUltraGrid.setGiaoDienVua()
        Me.DmnhanvienIUltraGrid.setChoPhepMenuStrip()
        Me.KetoantienmatIUltraGrid_DanhSach.setChoPhepMenuStrip()
        '=======================================================================
        'thêm tổng summaries
        Me.Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.setSummaries("doanhthu")
        Me.Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.setSummaries("thue")
        Me.Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.setSummaries("tongcong")
        Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.setSummaries("nguyente")
        Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.setSummaries("tienvnd")
        Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.setSummaries("tongcong")
        '=======================================================================
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub btnTaoMoi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTaoMoi.Click
        Me.KetoantienmatIUltraGrid_ThongTin.setMacDinh("ma", getMa)
        If (Me.KetoantienmatIUltraGrid_ThongTin.getTaoMoi()) Then
            Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.getLuuNgam()
        End If
    End Sub

    Private Sub btnLuu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLuu.Click
        If Me.KetoantienmatIUltraGrid_ThongTin.getLuu() Then
        End If
    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        Me.KetoantienmatIUltraGrid_ThongTin.getXoa()
    End Sub

    Private Sub btnLamTuoi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLamTuoi.Click
        Me.KetoantienmatIUltraGrid_ThongTin.getRefresh()
    End Sub

    Private Sub btnIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIn.Click
        'MessageBox.Show(Me.Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.Rows(2).ChildBands(0).Rows.SummaryValues("doanhthu").Value)
    End Sub

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        Me.Dispose()
        Me.Close()
    End Sub
    Private Sub Ketoantienmatchitiet_ThongTinChinh_TimKiem_IUltraGrid_ClickCell(sender As Object, e As Infragistics.Win.UltraWinGrid.ClickCellEventArgs) Handles Ketoantienmatchitiet_ThongTinChinh_TimKiem_IUltraGrid.ClickCell
        If Me.Ketoantienmatchitiet_ThongTinChinh_TimKiem_IUltraGrid.ActiveRow.Index <> -1 Then
            Try
                Me.KetoantienmatBindingSource.Position = Me.KetoantienmatBindingSource.Find("ma", Me.Ketoantienmatchitiet_ThongTinChinh_TimKiem_IUltraGrid.ActiveRow.Cells("ma").Value)
            Catch ex As Exception
            End Try
        End If
    End Sub

    Private Sub KetoantienmatIUltraGrid_ThongTin_AfterCellListCloseUp(sender As Object, e As Infragistics.Win.UltraWinGrid.CellEventArgs) Handles KetoantienmatIUltraGrid_ThongTin.AfterCellListCloseUp
        Try
            If KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("nghiepvu").IsActiveCell Then
                Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.setMacDinh("taikhoanno", Me.DmnghiepvuIUltraDropDown.ActiveRow.Cells("taikhoanno").Value)
                Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.setMacDinh("taikhoanco", Me.DmnghiepvuIUltraDropDown.ActiveRow.Cells("taikhoanco").Value)
                Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.setMacDinh("taikhoanvat", Me.DmnghiepvuIUltraDropDown.ActiveRow.Cells("taikhoanvat").Value)
            End If
            If KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("donvi").IsActiveCell Then
                Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.setMacDinh("donvi", Me.DmkhachhangIUltraDropDown.ActiveRow.Cells("ma").Value)
                Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.setMacDinh("diachi", Me.DmkhachhangIUltraDropDown.ActiveRow.Cells("diachi").Value)
                Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.setMacDinh("masothue", Me.DmkhachhangIUltraDropDown.ActiveRow.Cells("masothue").Value)
            End If
            If KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("bophan").IsActiveCell Then
                Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.setMacDinh("phongban", Me.DmphongbanIUltraDropDown.ActiveRow.Cells("ma").Value)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub KetoantienmatIUltraGrid_ThongTin_BeforeCellDeactivate(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles KetoantienmatIUltraGrid_ThongTin.BeforeCellDeactivate
        If Me.KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("nghiepvu").IsActiveCell Then
            Me.KetoantienmatIUltraGrid_ThongTin.getLuuNgam()
        End If
        If Me.KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("tinhtrang").IsActiveCell Then
            Me.KetoantienmatIUltraGrid_ThongTin.setFocusCellUltraGridNotNew(Me.KetoantienmatIUltraGrid_TienTe)
        End If
    End Sub

    Private Sub KetoantienmatIUltraGrid_TienTe_BeforeCellDeactivate(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles KetoantienmatIUltraGrid_TienTe.BeforeCellDeactivate
        If Me.KetoantienmatIUltraGrid_TienTe.ActiveRow.Cells("tienvnd").IsActiveCell Then
            Me.KetoantienmatIUltraGrid_TienTe.setFocusCellUltraGrid(Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid)
        End If
    End Sub
    Private Sub sumTienVND_ThongTinChinh()
        Dim tongcong As Decimal = 0
        Dim nguyente As Decimal = 0
        For index = 0 To Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.Rows.Count - 1
            Try
                tongcong += CDec(Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.Rows(index).Cells("tongcong").Value)
                nguyente += CDec(Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.Rows(index).Cells("nguyente").Value)
            Catch ex As Exception
                Exit For
            End Try
        Next
        Me.KetoantienmatIUltraGrid_TienTe.ActiveRow.Cells("tienvnd").Value = tongcong
        Me.KetoantienmatIUltraGrid_TienTe.ActiveRow.Cells("nguyente").Value = nguyente
    End Sub
    Private Sub sumTienVND_ThongTinKhaiThue()
        Dim tongcong As Decimal = 0
        Dim nguyente As Decimal = 0
        For index = 0 To Me.Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.Rows.Count - 1
            Try
                tongcong += CDec(Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.Rows(index).Cells("tongcong").Value)
                nguyente += CDec(Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.Rows(index).Cells("nguyente").Value)
            Catch ex As Exception
                Exit For
            End Try
        Next
        Me.KetoantienmatIUltraGrid_TienTe.ActiveRow.Cells("tienvnd").Value = tongcong
        Me.KetoantienmatIUltraGrid_TienTe.ActiveRow.Cells("nguyente").Value = nguyente
    End Sub
    Private Sub tinhDong_ThongTinChinh()
        If Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("nguyente").IsActiveCell Or Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("tienvnd").IsActiveCell And Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("nguyente").Value <> 0 And Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("nguyente").Value IsNot Nothing Then
            Try
                Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("tienvnd").Value = CDec(KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("tygia").Value) * CDec(Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("nguyente").Value)
                Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("doanhthu").Value = CDec(KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("tygia").Value) * CDec(Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("nguyente").Value)
            Catch ex As Exception
                Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("tienvnd").Value = 0
                Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("doanhthu").Value = 0
            End Try
            Try
                Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("thue").Value = CDec(Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("doanhthu").Value) * CDec(Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("phantramthue").Value) / 100
            Catch ex As Exception
                Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("thue").Value = 0
            End Try
            Try
                Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("tongcong").Value = CDec(Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("doanhthu").Value) + CDec(Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("thue").Value)
            Catch ex As Exception
                Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("tongcong").Value = 0
            End Try
        Else
            Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("doanhthu").Value = Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("tienvnd").Value
        End If
    End Sub
    Private Sub tinhDong_ThongTinKhaiThue()
        If Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.ActiveRow.Cells("doanhthu").IsActiveCell Or Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.ActiveRow.Cells("phantramthue").IsActiveCell Or Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.ActiveRow.Cells("thue").IsActiveCell Or Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.ActiveRow.Cells("tongcong").IsActiveCell Then
            Try
                Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.ActiveRow.Cells("thue").Value = CDec(Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.ActiveRow.Cells("doanhthu").Value) * CDec(Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.ActiveRow.Cells("phantramthue").Value) / 100
            Catch ex As Exception
                Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.ActiveRow.Cells("thue").Value = 0
            End Try
            Try
                Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.ActiveRow.Cells("tongcong").Value = CDec(Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.ActiveRow.Cells("doanhthu").Value) + CDec(Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.ActiveRow.Cells("thue").Value)
            Catch ex As Exception
                Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.ActiveRow.Cells("tongcong").Value = 0
            End Try
        End If
    End Sub
    Private Sub Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid_AfterExitEditMode(sender As Object, e As System.EventArgs) Handles Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.AfterExitEditMode
        'If Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.getCoThayDoiDuLieuKhong Then
        tinhDong_ThongTinKhaiThue()
        'sumTienVND_ThongTinKhaiThue()
        'End If
    End Sub

    Private Sub Ketoantienmatchitiet_ThongTinChinh_IUltraGrid_AfterExitEditMode(sender As Object, e As System.EventArgs) Handles Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.AfterExitEditMode
        'If Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.getCoThayDoiDuLieuKhong Then
        tinhDong_ThongTinChinh()
        'sumTienVND_ThongTinChinh()
        'End If
    End Sub

    Private Sub dmkhachhangultragrid_DoubleClickCell(sender As Object, e As Infragistics.Win.UltraWinGrid.DoubleClickCellEventArgs) Handles dmkhachhangultragrid.DoubleClickCell
        Try
            Me.KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("donvi").Value = dmkhachhangultragrid.ActiveRow.Cells("ma").Value
            Me.dmkhachhangultracomboeditor.CloseEditorButtonDropDowns()
            Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.setMacDinh("donvi", dmkhachhangultragrid.ActiveRow.Cells("ma").Value)
        Catch ex As Exception
        End Try
    End Sub

    Private Sub DmKhachHangIUltraGrid1_DoubleClickCell(sender As Object, e As Infragistics.Win.UltraWinGrid.DoubleClickCellEventArgs) Handles DmKhachHangIUltraGrid1.DoubleClickCell
        Try
            Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("donvi").Value = DmKhachHangIUltraGrid1.ActiveRow.Cells("ma").Value
            Me.dmkhachhangIUltraComBoEditor1.CloseEditorButtonDropDowns()
        Catch ex As Exception
        End Try
    End Sub

    Private Sub Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid_SummaryValueChanged(sender As Object, e As Infragistics.Win.UltraWinGrid.SummaryValueChangedEventArgs) Handles Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.SummaryValueChanged
        Try
            Me.KetoantienmatIUltraGrid_TienTe.ActiveRow.Cells("tienvnd").Value = Me.Ketoantienmatchitiet_ThongTinKhaiThue_IUltraGrid.Rows.SummaryValues("tongcong").Value
        Catch ex As Exception

        End Try
    End Sub
    Private Sub Ketoantienmatchitiet_ThongTinChinh_IUltraGrid_SummaryValueChanged(sender As Object, e As Infragistics.Win.UltraWinGrid.SummaryValueChangedEventArgs) Handles Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.SummaryValueChanged
        Try
            Me.KetoantienmatIUltraGrid_TienTe.ActiveRow.Cells("nguyente").Value = Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.Rows.SummaryValues("nguyente").Value
        Catch ex As Exception
            'Me.KetoantienmatIUltraGrid_TienTe.ActiveRow.Cells("nguyente").Value = 0
        End Try
        Try
            Me.KetoantienmatIUltraGrid_TienTe.ActiveRow.Cells("tienvnd").Value = Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.Rows.SummaryValues("tongcong").Value
        Catch ex As Exception

        End Try
        Try
            Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("tienvnd").Value = CDec(KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("tygia").Value) * CDec(Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("nguyente").Value)
            Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("doanhthu").Value = CDec(KetoantienmatIUltraGrid_ThongTin.ActiveRow.Cells("tygia").Value) * CDec(Me.Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("nguyente").Value)
        Catch ex As Exception
            'Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("tienvnd").Value = 0
            'Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("doanhthu").Value = 0
        End Try
        Try
            Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("thue").Value = CDec(Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("doanhthu").Value) * CDec(Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("phantramthue").Value) / 100
        Catch ex As Exception
            'Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("thue").Value = 0
        End Try
        Try
            Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("tongcong").Value = CDec(Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("doanhthu").Value) + CDec(Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("thue").Value)
        Catch ex As Exception
            'Ketoantienmatchitiet_ThongTinChinh_IUltraGrid.ActiveRow.Cells("tongcong").Value = 0
        End Try
    End Sub
    Private Function getThoat() As Boolean
        Try
            Me.Dispose()
            Me.Close()
            Return True
        Catch ex As Exception
            Return False
        End Try

    End Function
End Class